﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace NewBusiness.Utils
{
    public class LazyConnection : Lazy<IDbConnection>, IDisposable
    {
        public LazyConnection(string connectionString)
            : base(() =>
            {
                var c = new SqlConnection(connectionString);
                c.Open();

                return c;
            })
        {
        }

        public void Dispose()
        {
            if (IsValueCreated)
            {
                Value.Dispose();
            }
        }
    } 
}
